package com.biao.synchronized_test;

import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

//@Scope(value = "prototype")       // 设置成原型模式，多例的
@RestController
public class Test04_synchronized_springmvc {

    private AtomicInteger count = new AtomicInteger();

    @RequestMapping("/count")
    public synchronized String test() {     // 请求方法上添加 synchronized 让请求阻塞
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        count.getAndAdd(1);
        System.out.println("--------------" + count);
        return count.toString();
    }

}
